package Day4;

import java.util.Scanner;


public class Main {

    public static void main1 (String[] args) {

        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        String[] strings = s.split(" ");


        int A = (Integer.parseInt(strings[0]) + Integer.parseInt(strings[2])) / 2 ;
        int B = (Integer.parseInt(strings[1]) + Integer.parseInt(strings[3])) / 2;
        int C = (Integer.parseInt(strings[3]) - Integer.parseInt(strings[1])) / 2;

        if (A >=0 && B >=0 && C >= 0
                && A - B == Integer.parseInt(strings[0])
                && B - C == Integer.parseInt(strings[1])
                && A + B == Integer.parseInt(strings[2])
                && B + C == Integer.parseInt(strings[3])) {
            System.out.print(A + " " + B + " " + C);
        } else {
            System.out.print("No");
        }

    }

    public static void main (String[] args) {

        Scanner scanner = new Scanner(System.in);

        while (scanner.hasNextLine()) {
            String s = scanner.nextLine();
            String[] strings = s.split(" ");

            long M = Integer.parseInt(strings[0]);
            if(M == 0) {
                System.out.println(0);
                return;
            }

            long N = Integer.parseInt(strings[1]);

            StringBuilder stringBuilder = new StringBuilder();
            int mi = findBiggestMi(M, N);

            while (M != 0 && mi >= 0) {

                //得到该位上的数字
                int theNum = findTheNum(M, N, mi);

                stringBuilder.append(getTheNum(theNum));
                M -= Math.pow(N, mi) * theNum;
                mi--;

            }

            System.out.println(stringBuilder);
        }

    }

    //找到该位上对应的数字
    public static int findTheNum (long M, long N, int mi) {

        int ret = 1;

        while (M >= Math.pow(N, mi) * ret) {
            ret++;
        }

        return ret - 1;
    }

    //得到数字对应的字符串
    public static String getTheNum (int i) {
        if (i < 10) {
            return String.valueOf(i);
        } else {
            if (i == 10) {
                return "A";
            } else if (i == 11) {
                return "B";
            } else if (i == 12) {
                return "C";
            } else if (i == 13) {
                return "D";
            } else if (i == 14) {
                return "E";
            } else {
                return "F";
            }
        }
    }

    //寻找最高次幂
    public static int findBiggestMi (long M, long N) {

        int biggestMi = 0;

        while (M > Math.pow(N, biggestMi)) {
            biggestMi++;
        }

        return biggestMi - 1;
    }

}
